﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;


namespace MysqlTest
{
    public class Program
    {
        static public void PrintOrder(List<Order> list)
        {
            for (int i = 0; i < list.ToArray().Length; i++)
            {
                WriteLine(list[i]);
                for (int j = 0; j < list[i].OrderDetailsList.ToArray().Length; j++)
                    WriteLine("订单明细：" + list[i].OrderDetailsList[j]);

            }
        }

        static void Main(string[] args)
        {
            List<OrderDetail> details1 = new List<OrderDetail>()
            {
                new OrderDetail(101,"apple",1,1000,1),
                new OrderDetail(102,"banana",3,10,1)
            };//总价1030
            List<OrderDetail> details2 = new List<OrderDetail>()
            {
                new OrderDetail(201,"computer",1,3000,2),
                new OrderDetail(202,"notebook",2,70,2)
            };//总价3140

            Order order1 = new Order(1, "wang", details1);
            Order order2 = new Order(2, "li", details2);
            Order neworder2 = new Order(2, "zhao", details2);

            OrderService service = new OrderService();

            WriteLine("增加订单");
            service.AddOrder(order1);
            service.AddOrder(order2);
            WriteLine();


            List<Order> result = service.SearchOrder(2);
            WriteLine("搜索ID为2的订单：");
            PrintOrder(result);
            WriteLine();

            result = service.SearchOrder("CustomerID", "zhang");
            WriteLine("搜索顾客为zhang的订单：");
            PrintOrder(result);
            WriteLine();

            result = service.SearchOrder("ProductID", "computer");
            WriteLine("搜索产品为computer的订单：");
            PrintOrder(result);
            WriteLine();

            WriteLine("修改订单");
            service.ChangeOrder(neworder2);
            ReadKey();
        }
      }
    }